package cn.ito.zjgsu.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;

import cn.ito.zjgsu.constant.StatusCode;
import cn.ito.zjgsu.domain.ProjectType;
import cn.ito.zjgsu.domain.ProjectTypeExample;
import cn.ito.zjgsu.domain.wrapper.ProjectTypeWrapper;
import cn.ito.zjgsu.mapping.ProjectTypeMapper;
import cn.ito.zjgsu.service.ProjectTypeService;
import cn.ito.zjgsu.utils.StatusCodeUtil;
import cn.ito.zjgsu.utils.util.CollectionUtil;

@Service
@Transactional
public class ProjectTypeServiceImpl implements ProjectTypeService{
	
	@Resource
	private ProjectTypeMapper projectTypeMapper;
	
	
	//C------------------------------------------------------------------------------------------
	public String insertList(List<ProjectType> projectTypes){
		String status = StatusCode.FAILURE_STATUS;
		try {
			if(!CollectionUtil.isSafeEmpty(projectTypes)){
				projectTypeMapper.insertList(projectTypes);	
				status = StatusCode.SUCCESS_STATUS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			status = StatusCode.FAILURE_STATUS;
		}		
		return status;
	}
	
	
	//R------------------------------------------------------------------------------------------
	@Override
	public List<ProjectType> queryByPage(int pageNum, int records) {
		ProjectTypeExample projectTypeExample = new ProjectTypeExample();
		projectTypeExample.or().andPtDeleteTagsEqualTo(ProjectTypeWrapper.PROJECTTYPE_EXIST_FLAG);
		PageHelper.startPage(pageNum, records);
		return projectTypeMapper.selectByExample(projectTypeExample);
		
	}


	
	
	
	//U------------------------------------------------------------------------------------------
	@Override
	public String updateProjectByExample(ProjectType projectType, ProjectTypeExample projectTypeExample) {
		String status = StatusCode.FAILURE_STATUS;
		try {
			projectTypeMapper.updateByExampleSelective(projectType, projectTypeExample);
			status = StatusCode.SUCCESS_STATUS;
		} catch (Exception e) {
			e.printStackTrace();
			status = StatusCode.FAILURE_STATUS;
		}
		return status;
	}
	
	
	
	//D------------------------------------------------------------------------------------------
	@Override
	public String deleteProjectByExample(ProjectTypeExample projectTypeExample) {
		String status = StatusCode.FAILURE_STATUS;
		try {
			ProjectType projectType = new ProjectType();
			projectType.setPtDeleteTags(false);
			projectTypeMapper.updateByExampleSelective(projectType, projectTypeExample);
			status = StatusCode.SUCCESS_STATUS;
		} catch (Exception e) {
			e.printStackTrace();
			status = StatusCode.FAILURE_STATUS;
		}
		return status;
	}


	
	
	
}
